import baseVueRouter from 'lib-plugins/vueRouter';
import store from '../store'
import routes from './routes';
import { registerRoutes } from './registerRoutes'
const router = new baseVueRouter({
  token: () => {
    return store.state.common.token
  },
  constantRouter: [],
  whiteListRouter: routes,
  noAuthPath: '',
  errorPath: '',
  loginRedirectRouter: '',
  dynamicRouters: undefined,
  callBackLogin: null,
  callBackNoAuth: null,
  callBackError: null,
  callBackBeforeEach: (to, from, next) => {
    console.log('h5编辑器注册路由')
    console.log(to, 'to')
    console.log(from, 'from')
    return registerRoutes()
  },
  callBackBreadCrumb: (to, from, next) => {
    const breadCrumbs = [{
      name: to.meta.appName,
      path: ''
    }]
    const matched = to.matched
    for (let i = 0; i < matched.length; i++) {
      breadCrumbs.push({
        name: matched[i].meta.title,
        path: matched[i].path
      })
    }
    store.commit('setCommonStore', {
      breadCrumbs: breadCrumbs
    })
  },
  callBackAfterEach: null
}).initRouter()

export default router
